package com.example.bishe.demos.web;

import com.example.bishe.mapper.WorkerMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/register")
public class Zhuce_Controller {
    @Autowired
    private Worker worker;

    @PostMapping("/register")
    public Map<String, Object> register(@RequestBody Worker worker) {
        Map<String, Object> result = new HashMap<>();
        try {
            boolean saved = userService.save(worker);
            result.put("success",  saved);
            result.put("message",  saved ? "注册成功" : "注册失败");
        } catch (Exception e) {
            result.put("success",  false);
            result.put("message",  "系统错误：" + e.getMessage());
        }
        return result;
    }
}
